package tsing.javase.functionProgram.lamda;

import org.aspectj.weaver.ast.Var;

import java.util.function.Function;
import java.util.function.IntBinaryOperator;
import java.util.function.IntPredicate;

/**
 * @Author Tsing/吴清平
 * @Date 2022/12/29 15:06
 * @Version 1.0
 */
public class lamdaDemo {
    public static void main(String[] args) {

/*        new Thread(()->{
            System.out.println("thread.run()");
        }).start();*/



        //例子1：
        //原格式
      /*  int i = calculateNum(new IntBinaryOperator() {
            @Override
            public int applyAsInt(int left, int right) {
                return left + right;
            }
        });*/

        //lamda改造
     /*   int i = calculateNum((int left, int right) -> {
            return left + right;
        });

        System.out.println("result:" + i);*/

        //例子2：
       /* printNum(new IntPredicate() {
            @Override
            public boolean test(int value) {
                return true;
            }
        });*/

//        printNum((int value)->{return true;});


        /*int  s = typeConver(new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                return Integer.valueOf(s);
            }
        });*/


        String s = typeConver((String s1) -> {
            return s1;
        });

        System.out.println(s);


    }



    public static int calculateNum(IntBinaryOperator operator){
        int a = 20;

        int b = 30;

        return operator.applyAsInt(a,b);
    }


    public  static void printNum(IntPredicate predicate){
        int [] arr = {1,2,3,4,5,6,7,8,9,10};
        for (int i : arr) {
            if(predicate.test(i)) System.out.println(i);
        }
    }


    public static <R> R typeConver(Function<String,R> function){
        String str = "12345";
        R result = function.apply(str);
        return result;
    }
}
